function findMedianSortedArrays(nums1: number[], nums2: number[]): number {
    let allLength = nums1.length + nums2.length;
    let todoList: Array<number> = [];
    let todoLength = 0;
    let resultLength = 0;
    if (allLength % 2 === 0) {
        todoLength = allLength / 2 + 1;
        resultLength = 2;
    } else {
        todoLength = Math.floor(allLength / 2) + 1;
        resultLength = 1;
    }
    let a = 0;
    let index1 = 0;
    let flag1 = false;
    let b = 0;
    let index2 = 0;
    let flag2 = false;
    while(todoList.length < todoLength) {
        a = nums1[index1];
        b = nums2[index2];
        if (flag1) {
            todoList.push(a);
            index1++;
        } else if (flag2) {
            todoList.push(b);
            index2++;
        } else {
            if (a <= b) {
                if (index1 < nums1.length) {
                    todoList.push(a);
                    index1++;
                } else {
                    flag2 = true;
                    todoList.push(b);
                    index2++;
                }
            } else {
                if (index2 < nums2.length) {
                    todoList.push(b);
                    index2++;
                } else {
                    flag1 = true;
                    todoList.push(a);
                    index1++;
                }
            }
        }
    }
    let sum = 0;
    let count = 0;
    for(let i=0; i<resultLength; i++) {
        sum += todoList[todoLength - i - 1];
        count++;
    }
    return (sum / count);
};

let t1 = [1, 3];
let t2 = [2];
let t3 = [1, 2];
let t4 = [3, 4];
let t5 = [0, 0];
let t6 = [0, 0];
let t7 = [];
let t8 = [1];
let t9 = [2];

console.log(findMedianSortedArrays(t1, t2));
console.log(findMedianSortedArrays(t3, t4));
console.log(findMedianSortedArrays(t5, t6));
console.log(findMedianSortedArrays(t7, t8));
console.log(findMedianSortedArrays(t9, t7));